/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package utilidades;

import java.awt.event.KeyEvent;
import javax.swing.JTextField;
import pestañas.PanelPaso1;
import pestañas.PanelPaso2;

/**
 *
 * @author Lelouch
 */
public class ValidaBarras2 extends ValidaEnteros {
    int paso;
    int valorpanel = 0;
    int panel;
    boolean usado;

    public int getvalorpanel() {
        return valorpanel;
    }

    public ValidaBarras2(JTextField tf, int panel, int paso) {
        super(tf);
        usado = false;
        this.panel = panel;
        this.paso = paso;
    }

    @Override
    public void keyTyped(KeyEvent e) {
        bt.setVisible(false);
        super.keyTyped(e);
        char caracter = e.getKeyChar();

        if ((caracter < '0' || caracter > '9') && (caracter != KeyEvent.VK_BACK_SPACE && caracter != KeyEvent.VK_DELETE)) {
            bt.setVisible(true);
            e.consume();
        } else if ((caracter == KeyEvent.VK_BACK_SPACE || caracter == KeyEvent.VK_DELETE) && tf.getText().isEmpty()) {
            if (usado) {
                valorpanel = -1;
                usado = false;
//                switch(paso){
//                    case 1:{
//                        PanelPaso1.actualizarpanel(valorpanel, panel);
//                        break;
//                    }
//                    case 2:{
//                        PanelPaso2.actualizarpanel(valorpanel, panel);
//                    }
//                }

                
            } else {
                e.consume();
            }
        } else {
            if (tf.getText().isEmpty() && (caracter != KeyEvent.VK_BACK_SPACE && caracter != KeyEvent.VK_DELETE) && !usado) {
                valorpanel = 1;
                usado = true;
//                switch(paso){
//                    case 1:{
//                        PanelPaso1.actualizarpanel(valorpanel, panel);
//                        break;
//                    }
//                    case 2:{
//                        PanelPaso2.actualizarpanel(valorpanel, panel);
//                    }
//                }
            }
        }

    }
}
